<template>
  <div class="container">
    <div class="head-container item">
      <div class="title">人员报备管理</div>
      <el-button-group class="checkout-btn-group">
        <el-button class="checkout-btn" @click="queryTableData">
          <i class="el-icon-refresh"></i>
          <span>刷新</span>
        </el-button>
      </el-button-group>
      <div class="search-container">
        <el-input class="query-input"
                  placeholder="请输入姓名"
                  v-model="keywords"
                  clearable>
        </el-input>
        <el-button class="search-btn" @click="queryTableData">搜索</el-button>
      </div>

    </div>
    <div class="table-container item">
      <el-table
          :header-cell-style="{'text-align':'center'}"
          :cell-style="{'text-align':'center'}"
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column
            prop="base.name"
            label="姓名"
            width="120">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="base.gender"
            label="性别">
        </el-table-column>
        <el-table-column
            prop="base.phone"
            label="联系方式"
            width="160">
        </el-table-column>
        <el-table-column
            prop="reportTime"
            label="报备时间"
            width="120">
        </el-table-column>
        <el-table-column
            prop="returnDate"
            label="返回时间"
            width="120">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="destination"
            label="目的地"
            width="250">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="outMethod"
            label="出行方式">
        </el-table-column>
        <el-table-column
            :show-overflow-tooltip="true"
            prop="isOutCity"
            label="是否出市">
        </el-table-column>
        <el-table-column
            prop="isOutProvince"
            label="是否出省">
        </el-table-column>
      </el-table>
      <el-pagination
          class="pagination"
          background
          @size-change="handelSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :page-size="pageSize"
          :page-sizes="[5,10,15]"
          :current-page.sync="pageNum"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {queryReports} from "@/api/report";
import {formatDate} from "@/utils/date";

export default {
  name: "ReportManagementPage",
  data() {
    return {
      keywords: "",
      pageNum: 1,
      pageSize: 5,
      total: 0,
      tableData: []

    }
  },
  methods: {
    handleSizeChange(size) {
      this.pageSize = size;
      this.queryTableData();
    },
    handleCurrentChange(currentPage) {
      this.pageNum = currentPage;
      this.queryTableData();
    },
    queryTableData() {
      queryReports(this.pageNum, this.pageSize, this.keywords).then(res => {
        res.data.list.forEach(i => {
          i.reportTime = formatDate(new Date(i.reportTime), "yyyy-MM-dd");
          i.returnDate = formatDate(new Date(i.returnDate), "yyyy-MM-dd");
          i.isOutProvince = i.isOutProvince ? "是" : "否";
          i.isOutCity = i.isOutCity ? "是" : "否";

        })
        console.log(res)
        this.tableData = res.data.list;
        this.pageSize = res.data.pageSize;
        this.pageNum = res.data.pageNum;
        this.total = res.data.total;
      })
    },
  },
  mounted() {
    this.queryTableData();
  }
}
</script>

<style scoped>
.container {
  border-top: 3px solid #3c8dbc;
  border-radius: 3px;
  background-color: white;
  margin-left: 20px;
  margin-right: 20px;
}

.item {
  margin-right: 10px;
  margin-left: 10px;
}

.table-container {
  text-align: center;
}

.checkout-btn-group {

}

.checkout-btn {
  margin-top: 10px;
  margin-bottom: 10px;
}

.title {
  font-size: 20px;
  padding-top: 10px;
}

.pagination {
  padding-top: 20px;
  padding-bottom: 20px;
}

.search-container {
  display: inline-block;
  float: right;
}

.query-input {
  display: inline-block;
  margin-right: 10px;
  width: 180px;
}
</style>
